Skip to content

Add JSON help document generation and command examples#8

Merged
evanphx merged 1 commit into
mainfrom
mir-712-add-ability-to-generate-json-document-of-all-help
Feb 17, 2026
Merged

Add JSON help document generation and command examples#8
evanphx merged 1 commit into
mainfrom
mir-712-add-ability-to-generate-json-document-of-all-help

Conversation

@evanphx

@evanphx evanphx commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add HelpDoc() and HelpJSON() methods on both FlagSet and Dispatcher to generate structured help documentation as Go structs or JSON
  • Add ChoiceProvider interface for extracting valid choices from flag values
  • Add Example type, ExampleProvider interface, and WithExamples() command option for registering usage examples (exposed via JSON, not rendered in --help)
  • Recursive command tree traversal captures flags, positional args, rest args, flag groups, choices, and subcommands

Test plan

  • Basic flags (name, short, type, default, usage, isBool)
  • Choice flags with choices extracted
  • Positional args and rest args
  • Flag groups preserved in order
  • Nested/hierarchical commands with subcommands
  • Implicit namespaces (namespace-only paths)
  • Empty dispatcher and empty flag set
  • JSON marshal/unmarshal roundtrip
  • Standalone FlagSet.HelpJSON()
  • FromStruct integration with choices
  • Examples in help doc JSON and roundtrip
  • Examples omitted from JSON when absent
  • All existing tests pass

Add structured help documentation output as Go structs and JSON for
processing into documentation. Includes HelpDoc()/HelpJSON() methods
on both FlagSet and Dispatcher, with recursive command tree traversal,
flag metadata extraction (including choices via ChoiceProvider interface),
positional args, rest args, and flag groups.

Also adds Example type and ExampleProvider interface so commands can
register usage examples via WithExamples(), exposed through the help
document JSON but not rendered in --help output.
@evanphx evanphx requested a review from a team as a code owner February 14, 2026 04:00
@evanphx evanphx merged commit 3badc51 into main Feb 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants